package Q434

/**
 * 字符串中的单词数：
 * @author 23737
 * @date 2022.5.11
 */
class Main {

}

fun main(){
    val s = "hello, this is my world"
    val s1 = ""
    val countSegments = Solution().countSegments(s)
    println(Solution().countSegments(s1))
    println(countSegments)
}

class Solution {
    fun countSegments(s: String): Int {
        @Suppress("NAME_SHADOWING") val s = s.trim()
        if (s.isEmpty()){
            return 0
        }
        val split = s.split("\\s+".toRegex())
        return split.size
    }
}